<template>
  <div class="reports">
    <router-view></router-view>
     <div class="dashboard_empty" v-if="!reportList.length">
      <div>
        <img style="height: 432px" src="~@/assets/report_empty _page.jpg" class="empty_background_image" alt="empty_background_image">
      </div>
      You will see the reports after release time if you have access. <br/>
      Stay tuned.
    </div>
    <div class="report-title">
      Recent reports
    </div>
    <div class="report-card" v-for="item in reportList" :key="item.id" @click="toDetail(item)">
      <div class="avatar">
        <a-avatar
            size="large"
            v-if="item.avatar"
            slot="avatar"
            :src="item.avatar"
          />
      </div>
      <div class="content">
        <div class="title">{{ item.name }}</div>
        <div class="status-box font-roboto-regular">
          <div class="released-time">Reports was released on {{ item.release_time }}</div>
          <div class="start-time">Start on {{ item.start_time }}</div>
        </div>
      </div>
    </div>
    
  </div>
</template>

<script>
import { ideaReports } from '@/api/api'
import moment from "moment";

export default {
  name: 'Index',
  data () {
    return {
      reportList: [
      ],
    }
  },
  created () {
    ideaReports.list().then(res => {
      this.reportList = res.idea_reports.map(el => {
        const findUser = (res.users || []).find(user => user.id === el.user_id)
        return {
          ...el,
          release_time: moment(el.release_time).format('MMM DD, YYYY, hh:mm A'),
          start_time: moment(el.start_time).format('MMM DD, YYYY, hh:mm A'),
          avatar: findUser?.slack_user?.profile?.image_32,
          username: findUser?.slack_user?.profile?.real_name
        }
      })
      console.log(this.reportList);
    })
  },
  methods: {
    toDetail (item) {
      this.$router.push({
        path: '/Reports/detail',
        query: {
          id: item.id
        }
      })
    },
    
  }
}
</script>

<style scoped lang='less'>
.reports {
  height: 100%;
  position: relative;
  .dashboard_empty {
    width: 100%;
    height: 100%;
    background: #FFFFFF;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
    text-align: center;
    font-size: 24px;
    color: #919699;
    line-height: 36px;
  }
}
.report-card {
  background: #FFFFFF;
  border-radius: 4px 4px 4px 4px;
  opacity: 1;
  border: 1px solid #FFFFFF;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  margin: 12px 0;
  display: flex;
  padding: 24px;
  cursor: pointer;
  .ant-avatar {
    margin-right: 40px;
  }
  .title {
    font-size: 20px;
    font-family: Quicksand500;
    font-weight: bold;
    color: #5E6366;
    line-height: 28px;
    margin-bottom: 30px;
  }
  .status-box {
    display: flex;
    .released-time {
      border-radius: 4px 4px 4px 4px;
      background: linear-gradient(90deg, #FFECD2 0%, #FCB69F 100%);
      text-align: center;
      line-height: 23px;
      font-size: 14px;
      font-weight: 400;
      color: #3E4345;
      margin-right: 30px;
      padding: 0 20px;
      font-family: inherit !important;
    }
    .start-time {
      font-size: 14px;
      font-weight: 400;
      color: #3E4345;
      font-family: inherit !important;
    }
  }
}
</style>
